;+
; NAME:
;   path_join
;
; PURPOSE:
;   Join path elements using the default path separator, such as directory and filenames.
;
; CALLING SEQUENCE:
;   f = path_join(path1, path2) ; e.g. directory, path
;
; INPUTS:
;   path1, path2: Path elements.  The first must be a scaler. For example:
;       path1 could be a directory and path2 a filename.  Each element can contain 
;       path elements. path2 May be an array.
;
; OUTPUTS:
;   New path with all paths joined.
;
; EXAMPLE:
;   On UNIX:
;       IDL> print,path_join('/blah/stuff', 'tmp/things.txt')
;       /blah/stuff/tmp/things.txt
;
; MODIFICATION HISTORY:
;   Moved to main archive: 2007-04-22, Erin Sheldon, NYU
;
;-
;
;  Copyright (C) 2005  Erin Sheldon, NYU.  erin dot sheldon at gmail dot com
;
;    This program is free software; you can redistribute it and/or modify
;    it under the terms of the GNU General Public License as published by
;    the Free Software Foundation; either version 2 of the License, or
;    (at your option) any later version.
;
;    This program is distributed in the hope that it will be useful,
;    but WITHOUT ANY WARRANTY; without even the implied warranty of
;    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;    GNU General Public License for more details.
;
;    You should have received a copy of the GNU General Public License
;    along with this program; if not, write to the Free Software
;    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
;
;


function path_join, path1_in, path2

    n1=n_elements(path1_in) & n2=n_elements(path2)
    if n1 eq 0 or n2 eq 0 then begin
        print,'-Syntax: f = path_join(path1, path2)'
        on_error, 2
        message,'Halting'
    endif

    path1 = path1_in[0]
    if path1 eq '' then begin
        return, path2
    endif else begin
        return, filepath(root=path1, path2)
    endelse

end
